<template>
  <div id="wavemgmt" v-loading="loading">
    <v-tableTitle :btnConfig="btnConfig" :tableSelectData="tableSelectData" :title="$t('wave.wavemgmt')" @del="del"
      @sowingwall="sowingwall" @printing="printing" @waveprinting="waveprinting" @allocate="allocate" @deliver="deliver"
      @delete1="delete1" @waveReplenish="waveReplenish" @task="task"></v-tableTitle>
    <GTable ref="table" :hasCheck="true" :hasEdit="true" :showSummary="true" dateKey="adddate" api="queryWaveList" :otherHeight="0" :columnConfig="columnConfig" @selection-change="selectData" @setdialog="setdialog" > </GTable>
  </div>
</template>

<script type="text/ecmascript-6">
import tableTitle from "commons/TableTitle";
import table from "commons/Table";
import baseMixin from "@/mixins/BaseMixin";
import config from "./Config";
import bus from "../../../../bus/bus"
import print from '../../../../assets/js/print';
export default {
  name: "wavemgmt",
  mixins: [baseMixin, config],
  data() {
    return {
      loading: false,
      columnConfig:{ menu_id: 60, menu_code:"wavemgmt", menu_list_code:"wavemgmt"},
      tableSelectData: [],
    };
  },
  computed: {
    btnConfig() {
      return [
        { label: this.$t('common.delete'), certigier: !this.btnPermNameList.includes('WM05020301'), disabled: true, invalid: "del" },
        { label: this.$t('wave.sowingwall'), certigier: !this.btnPermNameList.includes('WM05020302'), disabled: true, invalid: "sowingwall" },
        { label: this.$t('wave.printing'), certigier: !this.btnPermNameList.includes('WM05020303'), disabled: true, invalid: "printing" },
        { label: this.$t('wave.waveprinting'), certigier: !this.btnPermNameList.includes('WM05020304'), disabled: true, invalid: "waveprinting" },
        {
          label: this.$t('out.action'), type: "more", certigier: !this.btnPermNameList.includes('WM05020305'), btnConfig: [
            { label: this.$t('out.allocation'), certigier: !this.btnPermNameList.includes('WM05020306'), disabled: true, invalid: "allocate" },
            { label: this.$t('out.revocation'), certigier: !this.btnPermNameList.includes('WM05020307'), disabled: true, invalid: "deliver" },
            { label: this.$t('wave.filterorder'), certigier: !this.btnPermNameList.includes('WM05020308'), disabled: true, invalid: "delete1" },
            { label: this.$t('wave.taskdown'), certigier: !this.btnPermNameList.includes('WM05020309'), disabled: true, invalid: "task" },
            /*{ label: "波次补货", certigier: this.allocateStatus, disabled: true, invalid: "waveReplenish" }*/
          ]
        },
      ]
    }
  },
  created() {
  },
  methods: {
    waveReplenish(data) {
      data.map(async (item, inex) => {
        try {
          let res = await this.$api.post(`/waveReplenish/${item.wavekey}`);
          
            this.$message.success(res.returnMgr);
            this.$refs.table.getTableData();
          
        } catch (e) {
          this.$message.error(e);
        }
      })
    },
    task(data) {
      data.map(async (item, inex) => {
        try {
          let res = await this.$api.get(`/waveReleaseTask/${item.wavekey}`);
          
            this.$message.success(res.returnMgr);
            this.$refs.table.getTableData();
          
        } catch (e) {
          this.$message.error(e);
        }
      })
    },
    delete1(data) {
      data.map(async (item, inex) => {
        try {
          let res = await this.$api.get(`/waveEliminateOrders/${item.wavekey}`);
          
            this.$message.success(res.returnMgr);
            this.$refs.table.getTableData();
          
        } catch (e) {
          this.$message.error(e);
        }
      })
    },
    deliver(data) {
      data.map(async (item, inex) => {
        try {
          let res = await this.$api.get(`/waveRevokeAllocate/${item.wavekey}`);
          
            this.$message.success(res.returnMgr);
            this.$refs.table.getTableData();
          
        } catch (e) {
          this.$message.error(e);
        }
      })
    },
    allocate(data) {
      data.map(async (item, inex) => {
        try {
          let res = await this.$api.post(`/allocateByWavekey/${item.wavekey}/${this.$store.state.wms}`, item);
          
            this.$message.success(res.returnMgr);
            this.$refs.table.getTableData();
          
        } catch (e) {
          this.$message.error(e);
        }
      })
    },
    async waveprinting(data) {
      /*let url = sessionStorage.getItem("url");
      let birtUrl = sessionStorage.getItem("birtUrl")
      let iframeUrl = `${url}/${birtUrl}/out?__report=report/RTX_bcfpjhd_report.rptdesign&wavekey=${data.wavekey}`
      this.$router.push({ name: "iframe", params: { url: iframeUrl } })*/
      /*for(let i = 0; i < data.length;i++){
        print.birtprint("BCFPJHD","wavekey=" + data[i].wavekey);
      }*/
      try {
        let res = await this.$api.get(`/getRtxtaskgrpByWave/` + data[0].wavekey);
        
          var orderlist = res.data.list;
          for (let i = 0; i < orderlist.length; i++) {
            console.log(orderlist[i]);
            var rtxtaskgrp = orderlist[i].rtxtaskgrp;
            print.bcgrfprint("BCFPJHD", rtxtaskgrp);
          }
          this.$refs.table.getTableData();
        
      } catch (e) {
        this.$message.error(e);
      }
    },
    async printing(data) {
      /*let url = sessionStorage.getItem("url");
      let birtUrl = sessionStorage.getItem("birtUrl")
      let iframeUrl = `${url}/${birtUrl}/out?__report=report/RTX_bcfpjhd_report.rptdesign&wavekey=${data.wavekey}`
      this.$router.push({ name: "iframe", params: { url: iframeUrl } })*/
      /*for(let i = 0; i < data.length;i++){
        print.birtprint("BCFPJHD","wavekey=" + data[i]);
      }*/
      try {
        let res = await this.$api.get(`/getordersByWave/` + data[0].wavekey);
        
          var orderlist = res.data.list;
          for (let i = 0; i < orderlist.length; i++) {
            console.log(orderlist[i]);
            var printdate = orderlist[i].printdate;
            var rtxsalesp = orderlist[i].rtxsalesp;
            if (rtxsalesp == 'TB') {
              print.sendTb(printdate);
            }
            if (rtxsalesp == 'PDD') {
              print.sendPdd(printdate);
            }
            if (rtxsalesp == 'JD') {
              print.sendJD(printdate);
            }
          }
          this.$refs.table.getTableData();
        
      } catch (e) {
        this.$message.error(e);
      }
    },
    async sowingwall(data) {
      try {
        let res = await this.$api.post(`/sowingWall`, data);
        
          this.$message.success(res.returnMgr);
          this.$refs.table.getTableData();
        
      } catch (e) {
        this.$message.error(e);
      }
    },
    selectData(data) {
      this.tableSelectData = data;
    },
    //删除
    async del(data) {
      try {
        let res = await this.$api.post(`/deleteWave`, data);
        
          this.$message.success(res.returnMgr);
            this.$refs.table.getTableData();
        
      } catch (e) {
        this.$message.error(e);
      }
    },
    //设置弹框
    setdialog(data) {
      this.$store.commit("setRouteData", data);
      this.$router.push({ name: 'wavemgmtDeawer' });
    },
  },
  mounted() {
    this.$store.commit("setSkip", {});
    this.$store.commit("setNewFlag", false);
    this.$store.commit("setTemporary", "");
    this.$store.commit("setRouteData", {});
  },
  watch: {
    tableSelectData(data) {
      if (this.permissionStatus) {
        if (data.length > 0) {
          this.deleteStatus = this.deliverStatus = false;
          this.allocateStatus = this.deleteOrderStatus = this.taskStatus = false;
        } else {
          this.deleteStatus = this.deliverStatus = true;
          this.allocateStatus = this.deleteOrderStatus = this.taskStatus = true;
        }
      }
    }
  },
  components: {
    "v-tableTitle": tableTitle,
  }
};
</script>

<style scoped>
#wavemgmt {
  width: 100%;
  height: 99%;
  padding-top: 6px;
}
</style>
